﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Controller;

namespace QLKS
{
    public partial class Frm_Main : Form
    {
   
        public string ID { get; set; }
        public string pass { get; set; }

        public Frm_Main()
        {
            InitializeComponent();

        }
        public void ChucNang(bool tr)
        {
            menu_Login.Enabled = tr;
            menu_Logout.Enabled = !tr;
            menu_Accounts.Enabled = !tr;

        }

        #region Menu Hệ Thống

        private void menu_Login_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmLogin)
                {
                    f.Activate();
                    return;
                }
            }
            FrmLogin frmlog = new FrmLogin();
            frmlog.MdiParent = this;
            frmlog.Show();
        }

        private void menu_Accounts_Click(object sender, EventArgs e)
        {
            
            foreach (Form f in MdiChildren)
            {
                if (f is FrmInfoUser)
                {
                    f.Activate();
                    return;
                }
            }
            FrmInfoUser frmIUser = new FrmInfoUser();
            frmIUser.sender(ID, pass);
            frmIUser.MdiParent = this;
            frmIUser.Show();
        }

        private void menu_Exit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        #endregion

        #region Menu Khách Hàng

        private void AddCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmCheckIn)
                {
                    f.Activate();
                    return;
                }
            }
            FrmCheckIn checkin = new FrmCheckIn();
            checkin.MdiParent = this;
            checkin.Show();
        }

        private void InfoCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmInfoCustomer)
                {
                    f.Activate();
                    return;
                }
            }
            FrmInfoCustomer infoCustomer = new FrmInfoCustomer();
            infoCustomer.MdiParent = this;
            infoCustomer.Show();

        }

        #endregion
    
        #region Menu Nhân Viên
        private void AddEmployeeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmAddEmployee)
                {
                    f.Activate();
                    return;
                }
            }
            FrmAddEmployee frmAdd = new FrmAddEmployee();
            frmAdd.MdiParent = this;
            frmAdd.Show();
        }

        private void InfoEmployeeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmInfoEmployee)
                {
                    f.Activate();
                    return;
                }
            }
            FrmInfoEmployee infoE = new FrmInfoEmployee();
            infoE.MdiParent = this;
            infoE.Show();
        }

        private void phânQuyềnQuảnLýToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmAccountType)
                {
                    f.Activate();
                    return;
                }
            }
            FrmAccountType acctype = new FrmAccountType();
            acctype.MdiParent = this;
            acctype.Show();

        }

        #endregion

        #region Menu Phòng

        private void RoomTypeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmRoomType)
                {
                    f.Activate();
                    return;
                }
            }
            FrmRoomType roomtype = new FrmRoomType();
            roomtype.MdiParent = this;
            roomtype.Show();
        }

        private void AddRoomToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmAddRoom)
                {
                    f.Activate();
                    return;
                }
            }
            FrmAddRoom addroom = new FrmAddRoom();
            addroom.MdiParent=this;
            addroom.Show();
        }

        private void InfoRoomToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmInfoRoom)
                {
                    f.Activate();
                    return;
                }
            }
            FrmInfoRoom infoRoom = new FrmInfoRoom();
            infoRoom.MdiParent = this;
            infoRoom.Show();

        }

        #endregion

        private void FrmMain_Load(object sender, EventArgs e)
        {

            
            PhanQuyenAdmin(false);
            ChucNang(true);
            foreach (Form f in MdiChildren)
            {
                if (f is FrmLogin)
                {
                    f.Activate();
                    return;
                }
            }
            FrmLogin frmlog = new FrmLogin();
            frmlog.MdiParent = this;
            frmlog.Show();
            
        }

        private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmAbout frmabout = new FrmAbout();
            frmabout.MdiParent = this;
            frmabout.Show();
        }

        private void menu_Logout_Click(object sender, EventArgs e)
        {
            DialogResult result = (MessageBox.Show("Bạn thật sự muốn đăng xuất khỏi chương trình", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question));
            if (result == DialogResult.OK)
            {
                CloseAllChildForm();
                ID = pass = null;
                ChucNang(true);
                PhanQuyenAdmin(false);
                MessageBox.Show("Đăng xuất thành công!!", "Thông báo");               
                FrmLogin frmlog = new FrmLogin();
                frmlog.MdiParent = this;
                frmlog.Show();
                
            }                
        }

        private void TimerTool_Tick(object sender, EventArgs e)
        {
            toolStrip_NgayThangNam.Text = DateTime.Now.ToShortDateString();
            toolStrip_GioPhutGiay.Text = DateTime.Now.ToLongTimeString();
            toollblAccount.Text = ID;
        }

        public void CloseAllChildForm()
        {
            foreach (Form f in this.MdiChildren)
            {
                f.Close();
            }
        }

        private void btnCheckRoom_Click(object sender, EventArgs e)
        {
            
            foreach (Form f in MdiChildren)
            {
                if (f is FrmCheckRoom)
                {
                    f.Activate();
                    return;
                }
            }
            FrmCheckRoom check = new FrmCheckRoom();
            check.MdiParent = this;
            check.Show();
        }

        private void btnAddCustomer_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmCheckIn)
                {
                    f.Activate();
                    return;
                }
            }
            FrmCheckIn checkin = new FrmCheckIn();
            checkin.MdiParent = this;
            checkin.Show();
        }

        private void btnPayment_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmInfoCustomer)
                {
                    f.Activate();
                    return;
                }
            }
            FrmInfoCustomer infoCustomer = new FrmInfoCustomer();
            infoCustomer.MdiParent = this;
            infoCustomer.Show();
        }

        private void btnDtatistics_Click(object sender, EventArgs e)
        {
            foreach (Form f in MdiChildren)
            {
                if (f is frmThongKe)
                {
                    f.Activate();
                    return;
                }
            }
            frmThongKe obj = new frmThongKe();
            obj.MdiParent = this;
            obj.Show();
        }

        public void PhanQuyenAdmin(bool tr)
        {
            CustomerToolStripMenuItem.Enabled = tr;
            EmployeeToolStripMenuItem.Enabled = tr;
            RoomToolStripMenuItem.Enabled = tr;
            btnCheckRoom.Enabled = tr;
            btnPayment.Enabled = tr;
            btnDtatistics.Enabled = tr;
        }

        public void PhanQuyenNV(bool tr)
        {
            CustomerToolStripMenuItem.Enabled = tr;
            btnCheckRoom.Enabled = tr;
            btnPayment.Enabled = tr;
            btnDtatistics.Enabled = tr;
        }


        private void Frm_Main_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F1 && btnCheckRoom.Enabled==true)
                btnCheckRoom_Click(sender, e);
            else if (e.KeyCode == Keys.F2 && btnPayment.Enabled == true)
                btnPayment_Click(sender, e);
            else if (e.KeyCode == Keys.F3 && btnDtatistics.Enabled == true)
                btnDtatistics_Click(sender, e);
        }


    }
}
